<?php
include_once ("../Login/databaseconnection.php");
$q=$_GET["q"];
$cs=explode(",",$q);
$Competition_Name=$cs[0];
$nam=$cs[1];
$tn=count($cs);
$hint='';
for($i=2;$i<$tn;$i++)
{
if(empty($adr))
{
$adr=$cs[$i];
}
else
{
$adr=$adr.",".$cs[$i];
}
}
$results= mysql_query("SELECT * FROM school Where Name='$nam' AND Address='$adr'");
if($row = mysql_fetch_array($results))
{
 $School_Id=$row['School_Id'];
}
		  $resultnet=mysql_query("SELECT * FROM competitions WHERE Competition_Name='$Competition_Name'");
  if($rownet=mysql_fetch_array($resultnet))
  {
		$Competition_Id=$rownet['Competition_Id'];
}
$resulttable = mysql_query("SELECT DISTINCT(Date) FROM competition WHERE School_Id='$School_Id' AND Competition_Id='$Competition_Id'");

if($resulttable)
{
$hint=$hint.'<select name="Date" id="Date">';
$hint=$hint.'<option value="Select One">Select One</option>';
while($rowtable = mysql_fetch_array($resulttable))
{
$Date=$rowtable['Date'];

$hint=$hint.'<option value="'.$Date.'">'.$Date.'</option>';
}
  $hint=$hint.'</select>';
  }
  if($hint=='')
{
  $hint=$hint.'<select name="Date" id="Date">';
   $hint=$hint.'<option value="Select One">Select One</option>';
	$com=mysql_query("SELECT DISTINCT(Date) FROM competition");
	while($row=mysql_fetch_array($com))
  {
	 $Dat=$row['Date'];
if($Date!=$Dat)
{
$hint=$hint.'<option value="'.$Dat.'">'.$Dat.'</option>';
}
  }
$hint=$hint.'</select>';
	  }
else
{
$response=$hint;
}
echo $response;
 ?>